package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo6 {
    public static void main(String[] args) {
        //需求:王克晶所带班级的信息，列出老师的名字，老师的性别，班级名，所在楼层
        /*
        SELECT t.name,t.gender,c.name,c.floor
        FROM teacher t
        JOIN class c ON c.teacher_id=t.id
        WHERE t.name='王克晶';
         */

        try(Connection conn = DBUtil.getConnection();) {
            Statement state= conn.createStatement();
            String s="SELECT t.name,t.gender,c.name,c.floor\n" +
                    "        FROM teacher t\n" +
                    "        JOIN class c ON c.teacher_id=t.id\n" +
                    "        WHERE t.name='王克晶';";
            ResultSet r=state.executeQuery(s);
            while(r.next()){
                String tname= r.getString("t.name");
                String tgender = r.getString("t.gender");
                String cname = r.getString("c.name");
                int cfloor = r.getInt("c.floor");
                System.out.println(tname+"---"+tgender+"---"+cname+"---"+cfloor);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
